<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Sms as Smslib;
use think\Db;
use think\Hook;

/**
 * 后台机器人接口
 */
class BackstageRobot extends Api
{
    protected $noNeedLogin = ['login','param_get','getchecksignlist','logchecksignresult'];
    protected $noNeedRight = ['*'];

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('app\api\model\DbCommon');
        
    }

    //1登录
    public function login(){
        //设置过滤方法
        $params = $this->request->post();
        $must_param = [
            "agentID",
            "password",
            "IP",
            "version",
        ];

        foreach ($must_param as $v){
            if(!isset($params[$v]) || empty($params[$v])){
                $this->error(__($v.'-是必传参数'),[],1);
            }
        }
        
        $out_column = [
            "res",
        ];
        //查询
        $procedure_name = 'backstagerobot_login';
        $rs = $this->model->mysql_procedure_execute($procedure_name,$must_param,$params,$out_column);
        if($rs['res']){
            $this->success('登录成功', $rs);
        }else{
            $this->error('登录失败',$rs);
        }
       
        /*
        //my_print($res);die;
        if($res[0]['res']){
            //echo 11;die;
            $account = $this->request->post('agentID');
            //echo $account;die;
            $password = '123456';
            if (!$account || !$password) {
                $this->error(__('Invalid parameters'),1);
            }
            $ret = $this->auth->login2($account, $password);
            if ($ret) {
                $data = ['userinfo' => $this->auth->getUserinfo()];
                $this->success(__('Logged in successful'), $data);
            } else {
                $this->error($this->auth->getError(),[],1);
            }
        }else{
            $this->error(__('登录失败'),[],1);
        }
         $this->success('返回成功', $res);
        */
    }

    //2读取机器人参数
    public function param_get(){
        //设置过滤方法
        $params = $this->request->post();
        $must_param = [
            "agentID",
        ];
        foreach ($must_param as $v){
            if(!isset($params[$v]) || empty($params[$v])){
                $this->error(__($v.'-是必传参数'),[],1);
            }
        }
        $out_column = [
            "checkInterval",
            "checkMaxTask",
        ];
        //查询
        $procedure_name = 'backstagerobot_param_get';
        $list = $this->model->mysql_procedure_execute($procedure_name,$must_param,$params,$out_column);
        $this->success('返回成功', $list);
    }

    //3-读取需要关注的用户列表
    public function getchecksignlist(){
        //设置过滤方法
        $params = $this->request->post();
        $must_param = [
            "agentID",
            "userCount",
        ];
        foreach ($must_param as $v){
            if(!isset($params[$v]) || empty($params[$v])){
                $this->error(__($v.'-是必传参数'),[],1);
            }
        }
        $out_column = [
            "userCheckNum",
        ];
        //查询
        $procedure_name = 'backstagerobot_get_check_list';
        $list = $this->model->mysql_procedure_execute($procedure_name,$must_param,$params,$out_column);
        $this->success('返回成功', $list);
    }

    //4-检查登记
    public function logchecksignresult(){
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        $params = $this->request->post();
        $must_param = [
            "agentId",
            "livestreamerID",
            "checkResult",
            "checkRemark",
        ];
        $out_column = [
            "res",
        ];
        foreach ($must_param as $k=>$v){
            if(!isset($params[$v])){
                $this->error(__($v.'-是必传参数'),[]);
            }
        }
        $procedure_name = 'backstagerobot_check_result_log';
        $rs = $this->model->mysql_procedure_execute($procedure_name,$must_param,$params,$out_column);
        if ($rs['res']){
            $this->success('登记检查结果成功', $rs);
        }else{
            $this->error('登记检查结果失败',$rs);
        }
    }
}
